﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.EntitesDAL
{
    public class CahocDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Cahoc");
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            var sql = "sp_Delete_Cahoc '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Cahoc)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Cahoc '{0}', '{1}', '{2}' ";
            sql = string.Format(sql, o.Maca, o.ThoigianBD, o.ThoigianKT);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Cahoc)obj;
            var sql = "set dateformat dmy; execute sp_Update_Cahoc '{0}', '{1}', '{2}' ";
            sql = string.Format(sql, o.Maca, o.ThoigianBD, o.ThoigianKT);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }


        public DataTable Search(DAL.Entities.Cahoc o)
        {
            string sql;
            if (o.Maca != "")
                sql = @"Select * From tb_Cahoc Where Maca like '%" + o.Maca + "%' and ThoigianBD like '%" + o.ThoigianBD + "%' and ThoigianKT like '%" + o.ThoigianKT + "%'   ";
            else
                sql = @"Select * From tb_Cahoc Where ThoigianBD like '%" + o.ThoigianBD + "%' and ThoigianKT like '%" + o.ThoigianKT + "%'   ";
            return ExecuteQuery(sql);
        }


        #endregion

        #region Other

        public DataTable Select_Max()
        {
            var sql = @"Select Max(Maca) as Ma From tb_Cahoc";
            return ExecuteQuery(sql);
        }

        #endregion
    }
}